using BuildingBlocks.Presentation.Endpoints;
using Catalog.Api;
using Catalog.Api.HostedServices;
using ServiceDefaults;

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

builder.Services.AddCatalogPresentation()
    .AddCatalogApplication()
    .AddCatalogInfrastructure();
           
builder.Services.AddHostedService<CatalogDataSeeder>();

builder.Services.AddEndpoints(typeof(DependencyInjection).Assembly);
var app = builder.Build();
app.MapDefaultEndpoints();

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI(options =>
    {
        options.OAuthClientId("res_server_catalog_service");
        options.OAuthClientSecret("res_server_catalog_service_secret");
        options.OAuthAppName("Catalog API");
        options.OAuthScopes("profile", "email", "roles", "offline_access");
    });
}

app.UseRouting();
app.UseHttpsRedirection();
app.UseCors("SpaCors");
app.UseAuthentication();
app.UseAuthorization();
app.MapEndpoints();
app.Run();
